package controllers

import (
	"errors"
	"go_wep_demo/common"

	"github.com/gin-gonic/gin"
)

var userNotLogin = errors.New("用户未登录")

// GetUserId 获取上下文中的user_id
func GetUserId(c *gin.Context) (userId int64, err error) {
	u, ok := c.Get(common.ContextUserId)
	if !ok {
		err = userNotLogin
		return
	}
	userId, ok = u.(int64)
	if !ok {
		err = userNotLogin
		return
	}
	return
}
